package com.xgq.drink.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xgq.drink.entity.OrderSnapshot;
import com.xgq.drink.mapper.OrderSnapshotMapper;
import com.xgq.drink.utils.RUtils;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xgq
 * @since 2025-03-04
 */
@RestController
@RequestMapping("/orderSnapshot")
public class OrderSnapshotController {
    @Autowired
    private OrderSnapshotMapper orderSnapshotMapper;

    @GetMapping("/getByOrderId")
    @Operation(summary = "根据订单ID查询快照", description = "获取指定订单的所有商品快照记录")
    public Object getSnapshotsByOrderId(@RequestParam String orderId) {
        try {
            return RUtils.success("查询成功", orderSnapshotMapper.selectList(
                    new QueryWrapper<OrderSnapshot>().eq("order_id", orderId)
            ));
        } catch (Exception e) {
            return RUtils.fail("查询失败: " + e.getMessage());
        }
    }
}
